#-*- coding: utf-8 -*-

# 測試python的def敘述，與函式的宣告

productNames = [ "JavaHome", "Thinking Python", "C#.NET" ]
productPrice = [ 550, 780, 300 ]

products = dict( zip( productNames, productPrice ) )
print products

# products[ "JavaHome" ] = 900

class User( object ):

	'''
	python可以根據值型時期的條件，動態的來決定同一個method要如何來實作
	def方法宣告，甚至可以宣告在if敘述中
	'''
	if products[ "JavaHome" ] <= 550:
		def buyJavaHome( self ):
			return "Buy JavaHome, price is " + str( products[ "JavaHome" ] )
	else:
		def buyJavaHome( self ):
			return "Too expensive, I don't want to buy JavaHome!"
			
	def buyBook( self, book ):
	
		# book是否存在於product的key中?
		if book in products:
			return "Buy " + book
		else:
			return "There doesn't have " + book
		
user   = User()
result = user.buyJavaHome()
print result

print user.buyBook( "Thinking Python" )
print user.buyBook( "Play Boy" )
